// app/controller/news.js
'use strict';


const Controller = require('egg').Controller;

// 定义创建接口的请求参数规则
const createRule = {
  type: 'number',
  type_id: 'number',
};

class ZanController extends Controller {
  async create() {
    const ctx = this.ctx;
    const { cms } = ctx.service;
    ctx.validate(createRule);
    try {
      const id = await cms.zan.create(ctx.request.body);
      const data = {
        id,
      };
      ctx.success({ data });
    } catch (error) {
      ctx.error({ detail: error });
    }
  }

  async destroy() {
    const ctx = this.ctx;
    const { cms } = ctx.service;
    try {
      const result = await cms.zan.destroy(ctx.params);
      const data = { result };
      ctx.success({ data });
    } catch (error) {
      ctx.error({ detail: error });
    }
  }
}

module.exports = ZanController;
